<template>
  <msg :showMsg="showEsign" @hide="hideSign">
    <div class="sy-kyc_message">
      <h3>{{signClick?'是否已完成以下协议的签署':'以下协议您是否确定授权外贸融'}}</h3>
      <p>
        <a class="slient-a" @click="showPtxy">《服务协议》</a>
      </p>
      <p>
        <a class="slient-a" @click="showYSxy">《隐私政策》</a>
      </p>
      <p>
        <a class="slient-a" @click="showSqs">《企业授权书》</a>
      </p>
      <p class="confirm-message" v-if="!signClick">确认授权需进行签署操作</p>
      <template v-else>
        <p class="confirm-error" v-if="doubleClick">您还未完成协议签署</p>
      </template>
    </div>

    <div class="sy-kyc_btn" v-if="!signClick">
      <el-button @click="hideSign">取消</el-button>
      <el-button
          type="primary"
          @click="sign"
      >
        前往签署
      </el-button>
<!--      <btn buttonText="前往签署" target="5" @btnSubmit="sign"></btn>-->
    </div>
    <div class="sy-kyc_btn" v-else>
      <!--    <btn v-if="doubleClick" buttonText="前往签署" target="5" @btnSubmit="sign"></btn>
     <btn buttonText="我已完成签署" target="5" @btnSubmit="goToSign"></btn>-->
      <el-button
          v-if="doubleClick"
          type="primary"
          @click="sign"
      >
        前往签署
      </el-button>
      <el-button
          type="primary"
          @click="goToSign"
      >
        我已完成签署
      </el-button>
    </div>
  </msg>
</template>

<script>
import Btn from '../btn'
import Msg from '../alert/msg';
import {esign} from '@/api/authen/agreed';
export default {
  components: {
    Msg,Btn
  },
  props: {
    showEsign:{
      type: Boolean
    },
    formObject:{
      type: Object
    }
  },
  data(){
    return {
      remainingTime: 5,
      doubleClick: false,
      signClick: false
    }
  },
  methods: {
    //调电子签章接口
    sign() {
      const loading = this.$loading({
        lock: true,
        text: '加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      esign(this.formObject).then(response=>{
        loading.close();
        if (response.code === 200) {
          window.open(response.data);
          this.signClick = true;
        } else {
          this.$message.error('签署失败！');
        }
      })
    },
    goToSign() {
      if (!this.signClick) {
        this.sign();
      } else {
        this.$emit('goSign');
      }
    },
    setParam() {
      this.doubleClick = true;
    },
    hideSign() {
      this.signClick = false;
      this.doubleClick = false;
      this.$emit('closeSign')
    },
    /***
     * 链接
     * 相关协议
     */
    showSqs(){
      window.open(window.location.origin+'/api/jfs/download/agreement/企业授权书.pdf/WMR');
    },
    showPtxy(){
      window.open(window.location.origin+'/api/jfs/download/agreement/外贸融平台服务协议.pdf/WMR');
    },
    showYSxy(){
      window.open(window.location.origin+'/api/jfs/download/agreement/隐私政策.pdf/WMR');
    }
  }
}

</script>
<style lang="scss">
.sy-kyc_message{
  width: 400px;
  height: 180px;
  padding: 10px 0 0 30px;
  .confirm-message{
    color: #b9b8b8;
  }
  .confirm-error{
    color: red;
    margin-bottom: 20px;
  }
  a.slient-a{
    text-decoration: none;
    margin-top: 28px;
  }
}
.sy-kyc_btn{
  margin-top: 28px;
  text-align: center;
  margin-bottom: 40px
}
</style>